<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <div class="btn-group">
        <button class="btn-green" onclick="rightCommit()">权限分配</button>
    </div>
</div>

<div class="bjui-pageContent">
    <table class="table table-bordered" id="deviceinfo" data-toggle="datagrid" data-options="{
        height: '100%',
        local: 'remote',
        showToolbar: false,
        postData:{id:${rid}},
        dataUrl: '/sysmanage/sysmodule/listdata.do',
        paging: {pageSize:20, pageCurrent:1},
        linenumberAll: false,
        filterThead:false,
        sortAll: true
    }">
        <thead>

        <tr>
            <th data-options="{render:rightcheck,align:'center'}" width="30px">
            </th>
            <th data-options="{name:'id',align:'center'}" width="150px">id</th>
            <th data-options="{name:'name',align:'center'}" width="70px">名称</th>
            <th data-options="{name:'parentid',align:'center'}" width="150px">所属上级</th>
        </tr>
        </thead>
    </table>
    <input type="hidden" value="${rid}" id="sysmodule-rid">
</div>
<script type="text/javascript">

    var rid=$("#sysmodule-rid").val();
    function rightcheck(value, data) {
        if(data.ischeck ==1){
            return '<input type="checkbox" class="icheckclass" checked="" data-toggle="icheck" value="' + data.id + '">'
        }else {
            return '<input type="checkbox" class="icheckclass" data-toggle="icheck" value="' + data.id + '">'
        }

    }
    function rightCommit() {
        var ichecks = $(".icheckclass");//获得选框值
        var arr=[];
        var index=0;
        for (var i = 0; i < ichecks.length; i++) {
            if (ichecks[i].checked == true) {
                arr[index]=ichecks[i].value;
                index++;
            }
        }
        commit(arr);
    }
    function commit(arr) {
        rid=$("#sysmodule-rid").val();
        console.log();
        $.ajax({
            type: "POST",
            url: "/sysmanage/sysmodule/setRoleRight.do?",
            //{"id":"1","name":"管理员","createdate":"1503642104000","memo":"管理员"}
            data:JSON.stringify({"arr":arr,"rid":rid}),
            dataType: 'json',
            cache: true,
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                if (data.Message === "ok") {
                    BJUI.alertmsg('ok', data.content)
                }
            }
        })
    }
</script>